package com.bootdo_jpa.system.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo_jpa.system.domain.AboutDO;
import com.bootdo_jpa.system.service.AboutService;
import com.bootdo_jpa.common.controller.BaseController;
import com.bootdo_jpa.common.utils.PageUtils;
import com.bootdo_jpa.common.utils.Query;
import com.bootdo_jpa.common.utils.R;

/**
 * 
 * 
 * @author huyidao
 * @email huyidao---123@163.com
 * @date 2019-05-06 19:54:48
 */
 
@Controller
@RequestMapping("/system/about")
public class AboutController extends BaseController {

	@Autowired
	private AboutService aboutService;
	
	@GetMapping()
	@RequiresPermissions("system:about:about")
	String About(){
	    return "system/about/about";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("system:about:about")
	public PageUtils list(@RequestParam Map<String, Object> params){
		PageUtils pageUtils = null;
    	try {
    		Query query = new Query(params);
    		pageUtils = aboutService.findAllByPage(query, AboutDO.class, "id");
		} catch (Exception e) {
			e.printStackTrace();
		}
        return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("system:about:add")
	String add(){
	    return "system/about/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("system:about:edit")
	String edit(@PathVariable("id") Long id,Model model){
		AboutDO about = aboutService.findById(id);
		model.addAttribute("about", about);
	    return "system/about/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("system:about:add")
	public R save( AboutDO about){
		try {
			aboutService.save(about);
			return R.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return R.error();
		}
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("system:about:edit")
	public R update( AboutDO about){
		try {
			aboutService.save(about);
			return R.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return R.error();
		}
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("system:about:remove")
	public R remove( Long id){
		try {
			aboutService.deleteById(id);
			return R.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return R.error();
		}
	}
	
	/**
	 * 批量删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:about:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		try {
			aboutService.deleteByIds(ids);
			return R.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return R.error();
		}
	}
	
}
